package model.workerwithfile;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

import org.apache.log4j.Logger;

import api.entitites.IDataBase;
import autoproperties.AutoProperties;

public class WriterInFile {

	private static ObjectOutputStream output;
	private static FileOutputStream file;
	private final static String UNSUCCESS = "Sorry, specified file not found, please, check properties and repeat";
	private static AutoProperties auto_properties = AutoProperties
			.getInstance();
	private static Logger log = Logger.getLogger(WriterInFile.class);

	public static void saveData(IDataBase db) {
		try {

			file = new FileOutputStream(new File(auto_properties.getFilePath()));
			output = new ObjectOutputStream(file);
			output.writeObject(db);
			file.close();
			output.close();

		} catch (IOException e) {
			log.error(UNSUCCESS);
			throw new RuntimeException(UNSUCCESS);
		}
	}

}
